package com.example.hospitalsystem.controller;

import com.example.hospitalsystem.pojo.dto.doctor.*;
import com.example.hospitalsystem.pojo.entity.Department;
import com.example.hospitalsystem.pojo.entity.Doctor;
import com.example.hospitalsystem.pojo.vo.PatientPrescriptionPharmacyVO;
import com.example.hospitalsystem.result.Result;
import com.example.hospitalsystem.service.DoctorService;
import com.example.hospitalsystem.service.RegistrationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/doctor")
@Tag(name="4.医生模块")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @Operation(summary = "根据接诊id查询对应的处方/药品", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/prescription/{id}")
    public Result<Object> selectpPescription(@PathVariable("id") Integer consultation){
        PatientPrescriptionPharmacyVO vo = doctorService.selectpPescriptionById(consultation);
        return Result.ok(vo);
    }

    @Operation(summary = "医生对患者分配处方/药品", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/shareOTC")
    public Result<Object> shareOTCTOPatient(@RequestBody DistributeMedicineDTO distributeMedicineDTO){
        return doctorService.shareOTCTOPatient(distributeMedicineDTO);
    }

    /**
     * 确认接诊挂号信息,将该条挂号记录从registration挂号表中移除，并存至consultation医生接诊表中
     * @param id
     * @return
     */
    @Operation(summary = "确认接诊挂号信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/checkRegistrationInfo/{id}")
    public Result<Object> checkRegistration(@PathVariable("id") Integer id){
        return doctorService.checkRegistration(id);
    }


    @Operation(summary = "医生分页获取确诊患者信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/doctorGetPatient")
    public Result<Object> doctorGetPatient(@RequestBody DoctorGetPatientDto doctorGetPatientDto){
        return doctorService.doctorGetPatient(doctorGetPatientDto);
    }

    @Operation(summary = "医生移除已缴费患者", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deletePayment/{id}")
    public Result<Object> deletePaymentById(@PathVariable("id") Integer consultationId){
        return doctorService.deletePaymentById(consultationId);
    }

    @Operation(summary = "医生修改自己信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/changeDoctorInfo")
    public Result<Object> changeDoctorInfo(@RequestBody ChangeDoctorDto changeDoctorDto){
        return doctorService.changeDoctorInfo(changeDoctorDto);
    }

    @Operation(summary = "医生完善个人信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/addDoctorInfo")
    public Result<Object> addDoctorInfo(@RequestBody Doctor doctor){
        return doctorService.addDoctorInfo(doctor);
    }

    @Operation(summary = "注销医生信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deleteDoctor/{password}")
    public Result<Object> deleteDoctor(@PathVariable("password") String password){
        return doctorService.deleteDoctorInfo(password);
    }


    @Operation(summary = "获取医生个人信息", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/doctorInfo")
    public Result<Object> getDoctorInfo(){
        return doctorService.getInfoByDoctor();
    }

    @Operation(summary = "根据id查询医生信息")
    @GetMapping("/doctorInfo/{id}")
    public Result<Object> getDoctorInfoById(@PathVariable("id") Integer doctorId){
        return doctorService.getDoctorInfoById(doctorId);
    }

    @Operation(summary = "返回医生列表")
    @GetMapping("/doctorList")
    public Result<Object> doctorList(){
        List<Doctor> list = doctorService.getDoctorList();
        return Result.ok(list);
    }

    @Operation(summary = "删除医生信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deleteDoctor/{id}")
    public Result<Object> deleteDoctor(@PathVariable("id") int id){
        return doctorService.deleteDoctor(id);
    }

    @Operation(summary = "管理员获取所有医生信息")
    @PostMapping("/getAlllDoctorInfo")
    public Result<Object> getAllDoctorInfo(@RequestBody DoctorPageQueryDto doctorPageQueryDto){
        return doctorService.getAllDoctorInfo(doctorPageQueryDto);
    }

    @Operation(summary = "搜索医生", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/search")
    public Result<Object> searchDoctor(String key){
        List<Doctor> list = doctorService.searchDoctor(key);
        return Result.ok(list);
    }

}
